/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package 解析.node.slicenode;

import 解析.ASCII;
import 解析.Matcher;

/**
 *
 * @author yanxi
 */
public class SliceIS extends SliceNode {

    public SliceIS(int[] buf) {
        super(buf);
    }

    int toLower(int c) {
        return ASCII.toLower(c);
    }

    @Override
    public boolean match(Matcher matcher, int i, CharSequence seq) {
        int[] buf = buffer;
        int x = i;
        for (int j = 0; j < buf.length; j++) {
            if (x >= matcher.to) {
                matcher.hitEnd = true;
                return false;
            }
            int c = Character.codePointAt(seq, x);
            if (buf[j] != c && buf[j] != toLower(c)) {
                return false;
            }
            x += Character.charCount(c);
            if (x > matcher.to) {
                matcher.hitEnd = true;
                return false;
            }
        }
        return next.match(matcher, x, seq);
    }
}
